<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <!--{include file='comm/header.tpl'}-->
    <title>投票列表</title>
</head>
<body>

<!--{include file='comm/naviBanner.tpl'}-->

<div class="container">

    <!--{include file='comm/menu.tpl'}-->
    <div class="comm_crub">
        <span class="now_crub">投票列表</span>
    </div>

    <div class="comm_content">

            <div  class="search-box">
                <div style="position:relative">
                    <form id="searchForm">
                        <table>
                            <tr>
                                <td>
                                    <span>
                                        投票类别：<select id="vote_category" name="vote_category">
                                            <option value="">请选择</option>
                                            <option value="1">首页问卷</option>
                                            <option value="2">会员中心</option>
                                            <option value="3">分类调查</option>
                                            <option value="4">购物流程</option>
                                        </select>
                                    </span>
                                    <span><input type="button" class="btn" value="查询" onclick="source.search();"></span>
                                    <span><input type="reset" class="btn" value="重置"></span>
                                </td>
                            </tr>
                        </table>
                    </form>
                </div>
            </div>

            <table id="flex" style="display:none"></table

        </div>


</div>

<script type="text/javascript">
    $("#flex").flexigrid({
        url:"/invokingAjax-backend/content/vote.ajax?operFlg=1",
        dataType: "json",
        colModel : [
            {display: "操作", width : 120, align: 'center'},
            {display: "投票类别", width : 100 },
            {display: "投票主题", width : 200},
            {display: "开始日期", width : 150 },
            {display: "结束日期", width : 150},
            {display: "投票次数", width : 100},
            {display: "多选", width : 100}
        ],
        buttons : [
            {name: "添加", bclass: "add", onpress : "source.add"},
            {separator: true},
            {name: "删除", bclass: "delete", onpress : "source.check"}
        ],
        usepager: true,
        rp: 10,
        useRp: true,
        showTableToggleBtn: true
    });

    var source = {
        //批量uuid组成数组
        vote_uuid: new Array(),

        search: function() {
            var dt = $('#searchForm').serializeArray();
            $("#flex").flexOptions({newp: 1, params: dt}).flexReload();
        },

        add: function() {
            E.open ("/quanliadmin/app/content/vote.pscript?operFlg=2");
        },

        edit: function(index) {
            var tr = $('#flex').find('tr')[index];
            var uuid_str = tr.id;
            vote_uuid = uuid_str.substr(3);
            E.open ("/quanliadmin/app/content/vote.pscript?operFlg=3&vote_uuid=" + vote_uuid);
        },

        detail: function(index){
            var tr = $('#flex').find('tr')[index];
            var uuid_str = tr.id;
            vote_uuid = uuid_str.substr(3);
            var vote_name = $('#flex').find('tr').eq(index).children().eq(2).children().html();
            E.open("/quanliadmin/app/content/vote.pscript?operFlg=4&vote_uuid=" + vote_uuid + "&vote_name=" + vote_name);
        },

        check: function(){
            //获取选中的行的行数
            var selected_count=$('.trSelected',flex).length;
            if (selected_count==0) {
                E.alert('请选择要删除的数据');
                return;
            } else {
                //用来接收uuid的临时变量
                var uuidArr = new Array();
                //将选中行的属性为id、属性值为'rowBF05D073DC4ABA5E1AE8EDC2228E1771'的属性值substr后传入uuidArr数组中
                for (var i=0;i<selected_count;i++){
                    uuid = $('.trSelected',flex).eq(i).attr('id').substr(3);
                    uuidArr[i] = uuid;
                }
                //将临时变量赋值给类变量uuidArr
                this.vote_uuid = uuidArr;

                //弹出确认层
                E.confirm('是否删除这 ' + $('.trSelected',flex).length + ' 条数据吗?', "source.del");
            }
        },

        del: function() {

            $.ajax({
                type: "POST",
                url:  "/invokingAjax-backend/content/vote.ajax?operFlg=5",
                data: "vote_uuid=" + this.vote_uuid,
                dataType: "JSON",
                success: function( result_obj ) {
                    if (result_obj.code == 200) {
                        $("#flex").flexReload();
                        E.alert(result_obj.message,  2);
                    } else {
                        E.alert(result_obj.message);
                    }
                }
            });
        },

        load: function() {
            $("#flex").flexReload();
        }

    };
</script>

</body>
</html>